//
//  NSData+Md5.m
//  familyeducation
//
//  Created by Chitanda Eru on 2017/3/7.
//  Copyright © 2017年 shangdingkeji. All rights reserved.
//

#import "NSData+Md5.h"
#import <CommonCrypto/CommonCrypto.h>

@implementation NSData (Md5)
- (NSString *)md5String
{
	const char *str = [self bytes];
	unsigned char result[CC_MD5_DIGEST_LENGTH];
	CC_MD5(str, (CC_LONG)self.length, result);
	
	NSMutableString *hash = [NSMutableString string];
	for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) {
		[hash appendFormat:@"%02X", result[i]];
	}
	
	return [hash lowercaseString];
}

@end
